package com.hospital.xiaochengxiu.yang.service.impl;

import com.hospital.xiaochengxiu.yang.dao.DepartmentCtDao;
import com.hospital.xiaochengxiu.yang.entity.DepartmentCt;
import com.hospital.xiaochengxiu.yang.service.DepartmentCtService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 检查业务类
 */
@Service
public class DepartmentCtServiceImpl implements DepartmentCtService {
    @Autowired
    private DepartmentCtDao departmentCtDao;
    /**
     * 查询检查报告
     * @param cdiagnoseNo 卡号
     * @return
     */
    @Override
    public List<DepartmentCt> selInspection(String cdiagnoseNo,Integer id) {
        return departmentCtDao.selInspection(cdiagnoseNo,id);
    }

    /**
     * 检查同一时间段是否有重复挂号
     *
     * @param userId   用户id [诊卡]
     * @param doctorId 医生id
     * @param date     日期
     * @param time     时间
     * @return true 无重复挂号
     */
    public boolean checkRegis(String userId, String doctorId, String date, String time) {
        return departmentCtDao.checkRegis(userId, doctorId, date + " " + time.substring(0, 5), date + " " + time.substring(6)) == 0;
    }


    /**
     * 查询每个时间段挂号的人数
     *
     * @param dateArr  时间段数组
     * @param doctorId 医生id
     * @param date     日期
     * @return 每个时间段的挂号人数
     */
    @Override
    public List<Integer> selDate(List<String> dateArr, Integer doctorId, String date) {
        List<Integer> regis = new ArrayList<>();
        for (int i = 0; i < dateArr.size(); i++) {
            String dateStr = dateArr.get(i);  //时间段
            Integer count = departmentCtDao.selDate(date + " " + dateStr.substring(0, 5), date + " " + dateStr.substring(6), doctorId);
            regis.add(count);
        }
        return regis;
    }
}
